﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using QdpzWtm.Models;
using QdpzWtm.Models.BaseSeting;


namespace QdpzWtm.ViewModels.ArticleManagementVMs
{
    public partial class ArticleManagementListVM : BasePagedListVM<ArticleManagement_View, ArticleManagementSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("ArticleManagement", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"", dialogWidth: 800),
                this.MakeStandardAction("ArticleManagement", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "", dialogWidth: 800),
                this.MakeStandardAction("ArticleManagement", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "", dialogWidth: 800),
                this.MakeStandardAction("ArticleManagement", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "", dialogWidth: 800),
                this.MakeStandardAction("ArticleManagement", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "", dialogWidth: 800),
                this.MakeStandardAction("ArticleManagement", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "", dialogWidth: 800),
                this.MakeStandardAction("ArticleManagement", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "", dialogWidth: 800),
                this.MakeStandardAction("ArticleManagement", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], ""),
            };
        }


        protected override IEnumerable<IGridColumn<ArticleManagement_View>> InitGridHeader()
        {
            return new List<GridColumn<ArticleManagement_View>>{
                this.MakeGridHeader(x => x.Title),
                this.MakeGridHeader(x => x.ArticleManagementTypeName_view),
                //this.MakeGridHeader(x => x.MainContent),
                this.MakeGridHeader(x => x.Author),
                this.MakeGridHeader(x => x.UpTime),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<ArticleManagement_View> GetSearchQuery()
        {
            var query = DC.Set<ArticleManagement>()
                .CheckContain(Searcher.Title, x=>x.Title)
                .CheckEqual(Searcher.ArticleManagementTypeId, x=>x.ArticleManagementTypeId)
                .CheckContain(Searcher.Author, x=>x.Author)
                .CheckBetween(Searcher.UpTime?.GetStartTime(), Searcher.UpTime?.GetEndTime(), x => x.UpTime, includeMax: false)
                .Select(x => new ArticleManagement_View
                {
				    ID = x.ID,
                    Title = x.Title,
                    ArticleManagementTypeName_view = x.ArticleManagementType.ArticleManagementTypeName,
                    //MainContent = x.MainContent,
                    Author = x.Author,
                    UpTime = x.UpTime,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class ArticleManagement_View : ArticleManagement{
        [Display(Name = "文章类型")]
        public String ArticleManagementTypeName_view { get; set; }

    }
}
